<!-- 搜索项目 -->
<template>
    <h-select-input-popup
      ref="hSelectInputPopup"
      v-model="val"
      v-bind="$attrs"
      v-on="$listeners"
      :params="queryParams"
      :keywords.sync="keywords"
      :getList="urlList"
          :disabled="disabled"
      @getDetail="getDetail"
          searchPlaceholder="请输入单据编号"
      @change="$emit('change', $event)"
          :isMulti="muitFlag"
    >
      <template v-slot:default="{ item }">
        <view class="project-item">
          <view class="option">
            <view class="lf">单据编号</view>
            <view class="rl">{{ item.billNo }}</view>
          </view>
          <!-- <view class="option">
            <view class="lf">签订单位</view>
            <view class="rl">{{ item.signUnit_dictText }}</view>
          </view> -->
          <view class="option">
            <view class="lf">关联项目</view>
            <view class="rl">{{ item.projectId_dictText }}</view>
          </view>
          <view class="option">
            <view class="lf">费用所属团队</view>
            <view class="rl">{{ item.feeTeamId_dictText }}</view>
          </view>
          <view class="option">
            <view class="lf">审核状态</view>
            <view class="rl">{{ item.bpmStatus_dictText }}</view>
          </view>
          <view class="option">
            <view class="lf">单据状态</view>
            <view class="rl">{{ item.billStatus_dictText }}</view>
          </view>

        </view>
      </template>
    </h-select-input-popup>
  </template>
  
  <script>
  import { queryOmcPrepareProjectList, queryOmcProjectList,erpReportAuditList } from '@/api/index.js'
  import { erpOmcProjectId, erpOmcProjectIds,erpReportAuditQueryById } from '@/api/index.js'
  import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'

  import address from '@/utils/address.js'
  export default {
    name: 'selectAuditFormListPopup',
    data() {
      return {
        address,
        params: {
          // order: 'desc',
          column: 'createTime',
          order: 'desc',
          pageNo: 1,
          pageSize: 10,
          billStatus: 'not_voided',
          bpmStatus:'3',
          billType:'create',
          permissionType:1
        },
        filterMultiDictText,
        initDictOptions,
        dictOptions: {},
        keywords: '',
      }
    },
    model: {
      prop: 'value',
      event: 'input',
    },
    props: {
      value: {
        type: [String, Number, Array],
        default: null,
      },
      signUnit: {
        type: String,
        default: '',
      },
      teamName2: {
        type: String,
        default: '',
      },
      projectStatus: {
        type: [String, Number, Array, Boolean],
        default: '',
      },
      api: {
        type: Function,
        default: queryOmcPrepareProjectList,
      },
          
          useType: {
              type: String,
              required: false,
              default: ''
          },
          dataIsolation: {
              type: String,
              required: false,
              default: ''
          },
          dataType: {
              type: String,
              required: false,
              default: ''
          },
          disabled: {
              type: Boolean,
              required: false,
              default: false,
          },
          proDisabled: {
              type: Boolean,
              required: false,
              default: false,
          },
          open: {
              type: Boolean,
              required: false,
              default: false,
          },
          changeStatus: {
              type: String,
              default: ''
          },
          muitFlag: {
        type: Boolean,
        default: false,
          },
          props: {
              type: Object,
              default: null,
          },
          isContractManager: {
              type: Boolean,
              default: false
          },
          // 是否是环评项目
          isBidding: {
              type: String,
              default: null
          },
          // 费用类型
          costType: {
              type: String,
              default: null
          },
          // 投标状态
          tenderStatus: {
              type: String,
              default: null
          },
          // 所属团队
          teamId: {
              type: String,
              default: null
          },
          
          // 项目承接人
          undertaker: {
              type: String,
              default: null
          },
          // 查询条件中团队字段名改为经营/生产团队
          queryParamType: {
              type: String,
              default: null
          },
          // 老系统项目录入标识
          isOldSystem: {
              type: String,
              default: ''
          },
    },
    created(){
       this.initDictConfig()
    },
    computed: {
      val: {
        get() {
          return this.value
        },
        set() {
          this.$emit('input', this.value)
        },
      },
          urlList () {
              var tmpUrl = queryOmcPrepareProjectList
              if (this.useType === 'tender') {
                  if (this.status == '2') {
                    //   tmpUrl = queryOmcProjectList
                      tmpUrl = erpReportAuditList
                  }
              } else {
                  if (this.status == '1') {
                      tmpUrl = queryOmcPrepareProjectList
                  } else{
                    //   tmpUrl = queryOmcProjectList
                      tmpUrl = erpReportAuditList
                  }
              }
              return tmpUrl
          },
      queryParams() {
              
        const result = {
          ...this.params,
        }
        if (this.projectStatus) {
        //   result.status = this.projectStatus
        }
        // if (this.dataIsolation) {
        //   result.dataIsolation = this.dataIsolation
        // }
        // if (this.dataType) {
        //   result.dataType = this.dataType
        // }
        if (this.signUnit) {
          // result.signUnit = this.signUnit
          result.companyId = this.signUnit
        }
              if (this.teamId) {
          result.teamName2 = this.teamId
        }
              if (this.costType) {
          result.costType = this.costType
        }
        if (this.keywords) {
          result.billNo = '*' + this.keywords + '*'
        }
              
              if (this.changeStatus) {
                //   result.changeStatus = this.changeStatus
              }
              if (this.tenderStatus) {
                  result.projectTenderStatus = this.tenderStatus
              }
              if(this.isBidding) {
                  result.isBidding = this.isBidding
              }
              if(this.undertaker) {
                  result.undertaker = this.undertaker
              }
              
              if(this.queryParamType=='2'){
                  result.isManagement = true
              }
              if(this.isOldSystem){
                  result.isOldSystem = this.isOldSystem
              }
              
            //   result.dataIsolation = this.dataIsolation
            //   result.dataType = this.dataType
        return result
      },
    },
    methods: {
      // 获取详情
      // getDetail(value) {
      //   erpOmcProjectId({ id: value }).then((res) => {
      //     if (res.success) {
      //       this.$refs.hSelectInputPopup.title = res.result.projectName
      //       this.$emit('select', {
      //         data: res.result,
      //         id: value,
      //       })
      //     }
      //   })
      // },
      initDictConfig() {
            initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
                if (res.success) {
                this.$set(this.dictOptions, 'teamId', res.result)
                }
            })

      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'empId', res.result)
        }
      })
    },
          getDetail(value) {
            if (this.muitFlag || value.split(',').length>0) {
              erpReportAuditQueryById({ id: value }).then((res) => {
                if (res.success) {
                  this.$refs.hSelectInputPopup.title = res.result.billNo
                  this.$emit('select', {
                    data: res.result,
                    id: value,
                  })
                }
              })
              return
            } else {
              erpOmcProjectId({ id: value }).then((res) => {
                if (res.success) {
                  this.$refs.hSelectInputPopup.title = res.result.billNo
                  this.$emit('select', {
                    data: res.result,
                    id: value,
                  })
                }
              })
            }
          },
  
      // 地址显示
      getAddress(areaCode) {
        var arr = areaCode.split(',')
        var addressDetail = ''
        this.address.map((value) => {
          if (arr[0] && value.code == arr[0]) {
            addressDetail = value.name
            value.children.map((val) => {
              if (arr[1] && val.code == arr[1]) {
                addressDetail = addressDetail + val.name
                val.children.map((item) => {
                  if (arr[2] && item.code == arr[2]) {
                    addressDetail = addressDetail + item.name
                  }
                })
              }
            })
          }
        })
        return addressDetail
      },
    },
  }
  </script>
  
  <style lang="scss" scoped>
  // 按钮
  .btn {
    position: fixed;
    bottom: 20rpx;
    width: 95%;
  }
  </style>
  